<!--title-->
<div class="mnav1">
    <div class="m_nav">
        <div class="nav_left">
            <em class="home_icon"><?=$this->sys_name?></em><span>&nbsp;&gt;&nbsp;</span><font><?=$this->title?></font>
        </div>
    </div>
</div>

<div class="content-table2">
    <div class="content-table-title"><?=$this->title?></div>
    <br />
    <div class="form-edit-task">

        <form action="/maozhua/hand-send-message-submit" method="post" name="theForm" onsubmit="submitform(this);return false;" id="theForm">
			<table border="0" cellspacing="0" cellpadding="0" style="margin-left:50px;">
				<tr>
				  <td style="width:150px;">发送内容</td>
				  <td><textarea name="content" id="content" style=" width:369px;" rows="7" cols="50" maxlength="140" placeholder="发送内容不得超过140个汉字"></textarea></td>
				</tr>
				<tr>
				  <td>发送类型</td>
				  <td>
					<input type="checkbox" name="pc" value="pc" /> 浏览器&nbsp;&nbsp;&nbsp;&nbsp;
					<input type="checkbox" name="wx" value="wx" /> 微信 &nbsp;&nbsp;&nbsp;&nbsp;(至少选择一项)
				  </td>
				</tr>
				<tr>
				  <td>接受对象</td>
				  <td>
					<input type='checkbox' value="true" id="quanxuan" onclick='SelectAll(this.value)'>&nbsp;全选
				  </td>
				</tr>
				<tr>
				  <td></td>
				  <td>
					<select multiple="multiple" size="10" name="user_ids[]" id="user_names" style="margin:0; width:375px;">
					  <?php foreach($this->data as $key => $row):?>
						  <option value="<?=$row['user_id']?>"><?=$row['user_name']?></option>
					  <?php endforeach;?>
					</select>
				  </td>
				</tr>
				<tr>
					<td></td>
					<td align="center">
						<br />
						<input type="button" class="buttonlong" value="发送" onclick="submitform();return false;" />
					</td>
				</tr>
			</table>
            <br /><br />
        </form>
    </div>
    <br/><br/>
</div>

<script>
function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}
var result = getQueryVariable("result");
//alert(result);
if(result == 2){
	alert('发送失败');
}
if(result == 1){
	alert('发送成功');
}

function submitform()
{
	var pc=document.getElementsByName('pc');
	var wx=document.getElementsByName('wx');
	var content  = document.getElementById('content');
	
	if(content.value.length==0 || content.value.trim()==''){
		alert('请填写要发送的内容');
		content.focus();
		return false;
	}

	//判断是否有选中项，默认为无
	var pcIsSel=false;
	var wxIsSel=false;
	
	if(pc[0].checked==true)
	{
		pcIsSel=true;
	}
	if(wx[0].checked==true)
	{
		wxIsSel=true;
	}
	if(pcIsSel==false && wxIsSel==false)
	{
		alert("请至少选择一个发送类型！");
		return false;
	}
	var select=document.getElementById("user_names");
	if(!select.value){
		alert("请选择要发送的用户");
		return false;
	}
	
	theForm.submit();
}

function SelectAll(res){
	if(res=='true'){
		for(var i=0;i<document.theForm.user_names.length;i++){
			document.theForm.user_names.options[i].selected=true;
		}
		$("#quanxuan").val('false');
	}else{
		for(var i=0;i<document.theForm.user_names.length;i++){
			document.theForm.user_names.options[i].selected=false;
			$("#quanxuan").val('true');
		}
	}
}
</script>
